import { BidBiddingApi } from "@/api/erp/bid/bidRecords";
import { SupplierApi } from "@/api/erp/purchase/supplier";
import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useRender, useTable } from "@/components/Table";
import { Tag } from "antd";
import "./index.less";
import { useTranslation } from "react-i18next";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.bid";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.unitCode`),
			component: "ApiSelect",
			field: "unitCode",
			componentProps: {
				api: SupplierApi.getSupplierSimpleList,
				labelField: "name",
				valueField: "suplerId"
				// immediate: false
			}
		},
		{
			label: t(`${en_vi}.isCompleted`),
			field: "isCompleted",
			component: "Select",
			componentProps: {
				options: [
					{ label: t(`${en_vi}.completed`), value: "1" },
					{ label: t(`${en_vi}.incomplete`), value: "0" }
				]
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.parentId`),
			dataIndex: "parentId"
		},
		{
			title: t(`${en_vi}.unitCode`),
			dataIndex: "unitCode"
		},
		{
			title: t(`${en_vi}.no`),
			dataIndex: "no"
		},
		{
			title: t(`${en_vi}.biddingDate`),
			dataIndex: "biddingDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.startDate`),
			dataIndex: "startDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.endDate`),
			dataIndex: "endDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.notes`),
			dataIndex: "notes"
		},
		{
			title: t(`${en_vi}.printCount`),
			dataIndex: "printCount"
		},
		{
			title: t(`${en_vi}.isCompleted`),
			dataIndex: "isCompleted",
			render: (_, { isCompleted }) => (
				<>
					{isCompleted == "0" ? (
						<Tag color="error">{t(`${en_vi}.incomplete`)}</Tag>
					) : (
						<Tag color="success">{t(`${en_vi}.completed`)}</Tag>
					)}
				</>
			)
		},
		{
			title: t(`${en_vi}.userId`),
			dataIndex: "userId"
		},
		{
			title: t("felix_ui.createdTime"),
			dataIndex: "createdTime",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`drugStorage.createdBy`),
			dataIndex: "createdBy"
		},
		{
			title: t("felix_ui.status"),
			dataIndex: "status",
			render: (_, { status }) => (
				<>{status == "0" ? <Tag color="success">{t(`felix_ui.open`)}</Tag> : <Tag color="error">{t(`felix_ui.close`)}</Tag>}</>
			)
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: BidBiddingApi.getBidBiddingPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 8 },
			actionColOptions: { span: 8 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setOrderItem(orderItem[0]?.id);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
